package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.SysCmsMaterial;
import com.ruoyi.cms.service.ISysCmsMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 媒体素材Controller
 * 
 * @author he
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/cms/material")
public class SysCmsMaterialController extends BaseController
{
    @Autowired
    private ISysCmsMaterialService sysCmsMaterialService;

    /**
     * 查询媒体素材列表
     */
    @PreAuthorize("@ss.hasPermi('cms:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCmsMaterial sysCmsMaterial)
    {
        startPage();
        List<SysCmsMaterial> list = sysCmsMaterialService.selectSysCmsMaterialList(sysCmsMaterial);
        return getDataTable(list);
    }

    /**
     * 导出媒体素材列表
     */
    @PreAuthorize("@ss.hasPermi('cms:material:export')")
    @Log(title = "媒体素材", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCmsMaterial sysCmsMaterial)
    {
        List<SysCmsMaterial> list = sysCmsMaterialService.selectSysCmsMaterialList(sysCmsMaterial);
        ExcelUtil<SysCmsMaterial> util = new ExcelUtil<SysCmsMaterial>(SysCmsMaterial.class);
        util.exportExcel(response, list, "媒体素材数据");
    }

    /**
     * 获取媒体素材详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysCmsMaterialService.selectSysCmsMaterialById(id));
    }

    /**
     * 新增媒体素材
     */
    @PreAuthorize("@ss.hasPermi('cms:material:add')")
    @Log(title = "媒体素材", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCmsMaterial sysCmsMaterial)
    {
        return toAjax(sysCmsMaterialService.insertSysCmsMaterial(sysCmsMaterial));
    }

    /**
     * 修改媒体素材
     */
    @PreAuthorize("@ss.hasPermi('cms:material:edit')")
    @Log(title = "媒体素材", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCmsMaterial sysCmsMaterial)
    {
        return toAjax(sysCmsMaterialService.updateSysCmsMaterial(sysCmsMaterial));
    }

    /**
     * 删除媒体素材
     */
    @PreAuthorize("@ss.hasPermi('cms:material:remove')")
    @Log(title = "媒体素材", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCmsMaterialService.deleteSysCmsMaterialByIds(ids));
    }
}
